package copyengine.utils.delayEffect
{
	import copyengine.scenes.viewport.ICEViewportListener;
	import copyengine.utils.delayEffect.logic.CEDelayEffectExecuteWarp;
	import copyengine.utils.delayEffect.logic.CEDelayEffectExecuteWarpManger;
	import copyengine.utils.delayEffect.logic.CEDelayEffectLayerManger;

	import flash.display.DisplayObjectContainer;

	public final class CEDelayEffectEngine
	{
		private var layerManger:CEDelayEffectLayerManger;
		private var warpManger:CEDelayEffectExecuteWarpManger;

		public function CEDelayEffectEngine()
		{
		}

		public function initialize(_gloableUILayer:DisplayObjectContainer):void
		{
			layerManger = new CEDelayEffectLayerManger();
			layerManger.initialize(_gloableUILayer);

			warpManger = new CEDelayEffectExecuteWarpManger();
			warpManger.initialize();
		}

		public function dispose():void
		{
			layerManger.dispose();
			warpManger.dispose();
		}

		/**
		 * <b>立即结束当前所有的特效</b></br></br>
		 * </br><b>注意!!! </b>结束特效及特效仍旧会回调Callback,比如当播放一个弹出金币的特效,
		 * 金币在地上一直停留(等待玩家捡起),但是一直没有捡起并且触发了切换场景(切换场景应触发该函数)
		 * 此时该函数会立刻结束所有特效并callback回调函数,回调函数会执行相应的数据层处理,保证玩家数据不因为
		 * 切换场景而丢失(像金币掉落这种逻辑此时后端已经计算完成,前端应为显示逻辑,如果前端没有捡起金币会导致和后端数据不同步)
		 */
		public function finishAllDelayEffectImmediately():void
		{
			warpManger.finishAllDelayEffectImmediately();
		}

		public function executeWarp(_warp:CEDelayEffectExecuteWarp, _flowFinishCallBack:Function):void
		{
			warpManger.addExecuteWarp(_warp, _flowFinishCallBack);
			_warp.setExecuteLayer(layerManger.getSceneUILayer(), layerManger.getSceneLayer(), layerManger.getGlobalUILayer());
			_warp.execute();
		}

		public function getViewportListener():ICEViewportListener
		{
			return layerManger;
		}

		public function getSceneLayerContainer():DisplayObjectContainer
		{
			return layerManger.getSceneLayerContainer();
		}

	}
}
